//
//  SpecialViewController.m
//  FlowerRainGarden
//
//  Created by 阿仁欧巴 on 16/4/15.
//  Copyright © 2016年 aren. All rights reserved.
//

#import "SpecialViewController.h"
#import "SearchViewController.h"
#import "FirstTableViewCell.h"
#import "SDWebImageManager.h"
#import "AppHeader.h"
#import "DetailViewController.h"
#import "LoginViewController.h"
#import "FamilyViewController.h"
#import "TitleModel.h"
#import "VideoViewController.h"

#define ColorWithRGB(r,g,b) [UIColor colorWithRed:r/255. green:g/255. blue:b/255. alpha:1]

@interface SDWebImageManager  (cache)


- (BOOL)memoryCachedImageExistsForURL:(NSURL *)url;

@end

@implementation SDWebImageManager (cache)

- (BOOL)memoryCachedImageExistsForURL:(NSURL *)url {
    NSString *key = [self cacheKeyForURL:url];
    return ([self.imageCache imageFromMemoryCacheForKey:key] != nil) ?  YES : NO;
}

@end

@interface SpecialViewController ()<UIGestureRecognizerDelegate, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>

@property (nonatomic, strong) UIButton *leftButton;
@property (nonatomic, assign) BOOL firstClick;//左按钮点击
@property (nonatomic, assign) BOOL centerClick;//中间按钮点击
@property (nonatomic, strong) UIButton *centerButton;
@property (nonatomic, strong) UIButton *searchButton;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) UIImageView *imageView;//左边下拉视图
@property (nonatomic, strong) UIImageView *centerImageView;//中间动画视图
@property (strong, nonatomic) UIView *topVIew;//导航栏遮盖视图
@property (nonatomic, strong) UIView *hiddenView;//点击中间按钮出现的遮盖视图
@property (nonatomic, assign) BOOL topClick;//头顶视图点击

@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) NSMutableArray *titleArray;
@property (nonatomic, strong) NSMutableArray *searchArray;

@property (nonatomic, strong) UISearchBar *searchBar;
@property (nonatomic, strong) UIView *hidView;

@property (nonatomic, strong) FamilyViewController *famlyVC;
@property (nonatomic, assign) BOOL appearFirst;//搜索框是否是第一次出现 默认是0 

@end

@implementation SpecialViewController

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _dataArray;
}
- (NSMutableArray *)titleArray
{
    if (!_titleArray) {
        _titleArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _titleArray;
}
- (NSMutableArray *)searchArray
{
    if (!_searchArray) {
        _searchArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _searchArray;
}

//请求数据
- (void)requestData
{
    
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [session POST:@"http://m.htxq.net/servlet/SysArticleServlet" parameters:@{@"action":@"mainList",@"currentPageIndex":@(0),@"isVideo":@"false",@"pageSize":@(20)} progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *mDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:nil];
        NSArray *array = mDic[@"result"];
        for (NSDictionary *dic in array) {
            FirstModel *model = [[FirstModel alloc] init];
            CategoryModel *cateModel = [[CategoryModel alloc] init];
            model.categoryModel = cateModel;
            [cateModel setValuesForKeysWithDictionary:dic[@"category"]];
            [model setValuesForKeysWithDictionary:dic];
            [self.dataArray  addObject:model];
        }
        
        [SVProgressHUD dismiss];

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
    
}

- (void)requestTitleData
{
    
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer = [AFHTTPResponseSerializer serializer];

    [session POST:@"http://m.htxq.net/servlet/SysCategoryServlet" parameters:@{@"action":@"getList"} progress:^(NSProgress * _Nonnull uploadProgress) {
        
        NSLog(@"%@",uploadProgress);
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *mDdic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
        NSArray *array = mDdic[@"result"];
//        NSLog(@"dic is %@",mDdic);
        for (NSDictionary *dic in array) {
            TitleModel *model = [[TitleModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.titleArray addObject:model];
        }
        [SVProgressHUD dismiss];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);

        [SVProgressHUD dismiss];
    }];

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.searchBar.text = nil;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    FamilyViewController *famVC = [[FamilyViewController alloc] init];
    self.famlyVC = famVC;
    
    [SVProgressHUD show];
    
    [self requestData];
    [self requestTitleData];
    
    [self createLeftBarItem];

    _firstClick = 0;//默认button没被点击时为0
    _centerClick = 0;
    _topClick = 0;
    

    
//创建导航栏视图
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.navigationController.navigationBar.width, self.navigationController.navigationBar.height)];
    topView.backgroundColor = [UIColor clearColor];
//创建导航栏的标题
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.width/2 - 170, 5, 40, 30)];
    titleLabel.text = @"专题";
    titleLabel.textAlignment = NSTextAlignmentRight;
    titleLabel.font = [UIFont systemFontOfSize:18];
    titleLabel.textColor =[UIColor blackColor];
    [topView addSubview:titleLabel];
    
//中间按钮
    UIButton *centerBtn = [self createButtonWithFrame:CGRectMake(titleLabel.x + 40, 10, 20, 20) type:UIButtonTypeCustom title:@"" target:self selector:@selector(centerBtnClick:) titleColor:nil];
    [centerBtn setBackgroundImage:[UIImage imageNamed:@"low.png"] forState:UIControlStateNormal];
    [topView addSubview:centerBtn];
//右边按钮
    UIButton *button = [self createButtonWithFrame:CGRectMake(0, 0, 20, 20) type:UIButtonTypeCustom title:@"" target:self selector:@selector(rightClick) titleColor:[UIColor blackColor]];
    [button setBackgroundImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.titleView = topView;

//创建遮盖层
    UIView *view = [[UIView alloc] init];
    view.hidden = YES;
    self.topVIew = view;
    view.backgroundColor = [UIColor clearColor];
    [self.navigationController.navigationBar addSubview:view];
//创建点击手势
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidden)];
    tap1.delegate = self;
    [view addGestureRecognizer:tap1];
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    view2.backgroundColor = [UIColor clearColor];
    view2.hidden = YES;
    [self.view addSubview:view2];
    self.hiddenView = view2;
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidden)];
    tap2.delegate = self;
    [view2 addGestureRecognizer:tap2];
    
    
//注册cell
    [_tableView registerClass:[FirstTableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

//搜索框的遮盖视图
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenSearchView)];
    tap3.delegate = self;
    UIView *hidView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, kWidth, kHeight - 64)];
    hidView.backgroundColor =[UIColor blackColor];
    hidView.alpha = 0.3;
    self.hidView = hidView;
    [self createSearchBar];
    self.searchBar.delegate = self;
    [hidView addGestureRecognizer:tap3];

    
    
}
//隐藏搜索框
- (void)hiddenSearchView
{
    self.searchBar.hidden = YES;
    self.hidView.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
}


#pragma mark ---创建搜索框---

- (void)createSearchBar
{
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 64)];
    self.searchBar.placeholder = @"请搜索";
    self.searchBar.searchBarStyle = UISearchBarStyleDefault;
    self.searchBar.barStyle = UIBarStyleDefault;
    _searchBar.hidden = YES;
    self.hidView.hidden = YES;
    [self.view addSubview:self.hidView];
    [self.view addSubview:_searchBar];

   
}

#pragma mark ---开始编辑的时候

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    [self.famlyVC.dataArray removeAllObjects];
    NSLog(@"%@",_famlyVC.dataArray);
    //请求搜索到的数据
    [self requestData];
    self.searchArray = self.dataArray;
    
       if (_searchBar == searchBar) {
        [_searchBar setShowsCancelButton:YES animated:YES];
        for (UIView *view in [searchBar.subviews firstObject].subviews) {
            if ([view isKindOfClass:[UIButton class]]) {
                UIButton *cancelButton = (UIButton *)view;
                [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
                [cancelButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
            }
        }
        
    }
        return YES;
}



//取消按钮的点击事件
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    self.navigationController.navigationBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:NO];
    self.hidView.hidden = YES;
}


#pragma mark ----会实时响应搜索栏内容的变换  搜索的方法----------
#warning mark ----之前搜锁之后没有数据 是因为跳转的控制器对象 不相同 ----



- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    
//    searchText = self.searchBar.text;
    
    [_famlyVC.dataArray removeAllObjects];
    NSLog(@"%@",_famlyVC.dataArray);
    
    for (int i = 0; i < self.searchArray.count; i++) {
        
        FirstModel *model1 = self.searchArray[i];
        
        NSLog(@"data = %@",_famlyVC.dataArray);

        if (model1.keywords.length >= searchText.length) {
            
            
            if([model1.keywords rangeOfString:searchText].location != NSNotFound)//_roaldSearchText
            {
                [_famlyVC.dataArray addObject:model1];
                NSLog(@"array = %@",_famlyVC.dataArray);
                
            }
            else
            {
                NSLog(@"no");
            }
            
        }
    }
  
    [_famlyVC.tableView reloadData];
}

#pragma  mark --当键盘搜搜按钮被点击时 ----

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    NSLog(@"你好");
    [self.navigationController pushViewController:_famlyVC animated:YES];
    
    
}

//右边搜索按钮的点击方法
- (void)rightClick
{
    [self resignFirstResponder];
    self.navigationController.navigationBar.hidden = YES;
    self.searchBar.hidden = NO;
    self.hidView.hidden = NO;
    [_searchBar becomeFirstResponder];
}




#pragma mark ----tableView 的 delegate datasource -----


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 250;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

    return cell;
}

#pragma mark ---点击cell 的方法 ---

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FirstModel *model = self.dataArray[indexPath.row];
    DetailViewController *detailVC = [[DetailViewController alloc] init];
    [self.navigationController pushViewController:detailVC animated:YES];
    detailVC.model = model;
}



//添加每个cell出现时的3D动画
- (void)tableView:(UITableView *)tableView willDisplayCell:(FirstTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    
    FirstModel *model = self.dataArray[indexPath.row];
    
    if (![[SDWebImageManager sharedManager] memoryCachedImageExistsForURL:[NSURL URLWithString:model.smallIcon]]) {
        
        CATransform3D rotation;//3D旋转
        
        rotation = CATransform3DMakeTranslation(0 ,50 ,20);
        //        rotation = CATransform3DMakeRotation( M_PI_4 , 0.0, 0.7, 0.4);
        //逆时针旋转
        
        rotation = CATransform3DScale(rotation, 0.9, .9, 1);
        
        rotation.m34 = 1.0/ -600;
        
        cell.layer.shadowColor = [[UIColor blackColor]CGColor];
        cell.layer.shadowOffset = CGSizeMake(10, 10);
        cell.alpha = 0;
        
        cell.layer.transform = rotation;
        
        [UIView beginAnimations:@"rotation" context:NULL];
        //旋转时间
        [UIView setAnimationDuration:0.6];
        cell.layer.transform = CATransform3DIdentity;
        cell.alpha = 1;
        cell.layer.shadowOffset = CGSizeMake(0, 0);
        [UIView commitAnimations];
    }
    
    [cell cellOffset];
    cell.model = model;
}

//表视图滚动时

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    
        NSArray<FirstTableViewCell *> *array = [self.tableView visibleCells];
    
        [array enumerateObjectsUsingBlock:^(FirstTableViewCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            [obj cellOffset];
        }];
            
}


//创建左边按钮
- (void)createLeftBarItem

{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"leftBarItemImage"] forState:UIControlStateNormal];
    button.size = CGSizeMake(20, 20);
    [button addTarget:self action:@selector(showAnimationView) forControlEvents:UIControlEventTouchUpInside];
// 修改导航栏左边的item
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.leftButton = button;
    
}



//手势的点击方法

- (void)hidden
{
    _firstClick = 0;
    if (0 == _topClick) {
        [UIView animateWithDuration:0.5 animations:^{
            _centerImageView.frame = CGRectMake(self.view.width / 2 - 20, -100, 100, 100);
            _centerClick = 0;
            [_centerButton setBackgroundImage:[UIImage imageNamed:@"low.png"] forState:UIControlStateNormal];
            _imageView.frame = CGRectMake(0, -self.view.height, self.view.width, self.view.height);
            _imageView.alpha = 0;
            [_leftButton setBackgroundImage:[UIImage imageNamed:@"leftBarItemImage"] forState:UIControlStateNormal];
            _firstClick = 0;
        } completion:^(BOOL finished) {
            _topVIew.hidden = YES;
            _hiddenView.hidden = YES;
        }];
        
        _topClick = 0;

        NSLog(@"dianji %d",_topClick);
    } else if (_topClick == 1) {
        
        NSLog(@"heihei %d",_topClick);
    }


}

//左边按钮的点击方法
- (void)showAnimationView
{
    
    _topVIew.frame =CGRectMake(50, 0, self.view.width - 30, 44);
    if (0 == _firstClick) {
        //点击出现图片
        _topVIew.hidden = NO;
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -self.view.height, self.view.width, self.view.height)];
        _imageView.userInteractionEnabled = YES;
        [self.view addSubview:_imageView];
        
        [self setImageButtonWithframe:CGRectMake((self.view.width - 100) / 2, 150, 100, 30) title:@"家居庭院" target:self selector:@selector(familyGarden)];
        [self setImageButtonWithframe:CGRectMake((self.view.width - 100) / 2, 200, 100, 30) title:@"缤纷小物" target:self selector:@selector(littleThing)];
        [self setImageButtonWithframe:CGRectMake((self.view.width - 100) / 2, 250, 100, 30) title:@"跨界鉴赏" target:self selector:@selector(lookLook)];
        [self setImageButtonWithframe:CGRectMake((self.view.width - 100) / 2, 300, 100, 30) title:@"花田秘籍" target:self selector:@selector(follower)];
        [self setImageButtonWithframe:CGRectMake((self.view.width - 100) / 2, 350, 100, 30) title:@"城市微光" target:self selector:@selector(cityLight)];
        
        _imageView.backgroundColor = [UIColor whiteColor];
        [UIView animateWithDuration:0.5 animations:^{
            _imageView.frame = CGRectMake(0, 64, self.view.width, self.view.height - 96);
            _imageView.alpha = 0.9;
//            _leftButton.transform = CGAffineTransformMakeRotation(M_PI / 2);
            [_leftButton setBackgroundImage:[UIImage imageNamed:@"侧边栏副本.png"] forState:UIControlStateNormal];

        }];
        _firstClick = 1;
        NSLog(@"出现%d",_firstClick);
        
    } else if (_firstClick == 1) {
        self.topVIew.hidden = YES;
        [UIView animateWithDuration:0.5 animations:^{
            _imageView.frame = CGRectMake(0, -self.view.height, self.view.width, self.view.height);
            _imageView.alpha = 0;
            [_leftButton setBackgroundImage:[UIImage imageNamed:@"leftBarItemImage"] forState:UIControlStateNormal];

        }];

        _firstClick = 0;
        NSLog(@"左点击%d",_firstClick);
    }

    
}


//中间按钮的点击方法
- (void)centerBtnClick:(UIButton *)sender {
    
    _centerButton = sender;
    
    _topVIew.frame = CGRectMake(0, 0, self.view.width, 44);
    _topVIew.hidden = NO;
    _hiddenView.hidden = NO;
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.width / 2 - 20, -64, 100, 100)];
    imageView.alpha = 0.8;
//    [_hiddenView addSubview:imageView];
    //添加文章和视屏按钮
    UIButton *contextButton = [self createButtonWithFrame:CGRectMake(20, 20, 60, 20) type:UIButtonTypeCustom title:@"文章" target:self selector:@selector(context) titleColor:[UIColor blackColor]];
    UIButton *videoButton = [self createButtonWithFrame:CGRectMake(20, 60, 60, 20) type:UIButtonTypeCustom title:@"视频" target:self selector:@selector(video) titleColor:[UIColor blackColor]];
    [imageView addSubview:contextButton];
    [imageView addSubview:videoButton];
    
    if (0 == _centerClick) {
        //添加分类视图

        [UIView animateWithDuration:0.3 animations:^{
            [sender setBackgroundImage:[UIImage imageNamed:@"upImage"] forState:UIControlStateNormal];
            imageView.backgroundColor = [UIColor whiteColor];
            imageView.frame = CGRectMake(self.view.width / 2 - 20, 64, 100, 100);
            imageView.layer.cornerRadius = 10;
            imageView.userInteractionEnabled = YES;
            imageView.alpha = 0.9;
            [self.view addSubview:imageView];
            _centerImageView = imageView;
        } completion:^(BOOL finished) {
            imageView.hidden = NO;
        }];
        
        _centerClick = 1;
        
    } else if (1 == _centerClick) {

        [UIView animateWithDuration:0.3 animations:^{
            [_centerButton setBackgroundImage:[UIImage imageNamed:@"low.png"] forState:UIControlStateNormal];
            _centerImageView.alpha = 0.1;
            _centerImageView.frame = CGRectMake(self.view.width / 2 - 20, -64, 100, 100);
            
        } completion:^(BOOL finished) {

        
        }];

        _centerClick = 0;
    }
    
}



//创建button的方法

- (UIButton *)createButtonWithFrame:(CGRect)frame type:(UIButtonType)type title:(NSString *)title target:(id)target selector:(SEL)selector titleColor:(UIColor *)titleColor
{
    UIButton *button1 = [UIButton buttonWithType:type];
    button1.frame =frame;
    [button1 setTitle:title forState:UIControlStateNormal];
    [button1 addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    return button1;
}

#pragma mark ----文章和视频------
//文章按钮点击
- (void)context
{
    
    NSLog(@"文章");
}
//视频按钮
- (void)video
{
    NSLog(@"跳转到视频页面");
    VideoViewController *videoVC = [[VideoViewController alloc] init];
    [self.navigationController pushViewController:videoVC animated:YES];
}

#pragma mark ---左边下拉视图添加按钮的方法---
//设置动画视图中按钮的方法
- (void)setImageButtonWithframe:(CGRect)frame title:(NSString *)title target:(id)target selector:(SEL)selector
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.backgroundColor = [UIColor redColor];
    button.frame = frame;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    [self.imageView addSubview:button];
    
}

#pragma mark ----5个按钮的点击方法------


- (void)familyGarden
{
    NSLog(@"家庭");
    
    FamilyViewController *familyVC = [[FamilyViewController alloc] init];
        TitleModel *model = self.titleArray[0];
        familyVC.ID = model.ID;
        NSLog(@"model = %@",model.name);
    [self.navigationController pushViewController:familyVC animated:YES];

    
}

- (void)littleThing
{
    NSLog(@"littleThing");
    FamilyViewController *familyVC = [[FamilyViewController alloc] init];
    [self.navigationController pushViewController:familyVC animated:YES];
    TitleModel *model = self.titleArray[1];
    familyVC.ID = model.ID;
    NSLog(@"model = %@",model.name);
    NSLog(@"id = %@",familyVC.ID);
}
- (void)lookLook
{
    NSLog(@"look");
    FamilyViewController *familyVC = [[FamilyViewController alloc] init];
    [self.navigationController pushViewController:familyVC animated:YES];
    TitleModel *model = self.titleArray[2];
    familyVC.ID = model.ID;
    NSLog(@"model = %@",model.name);
    NSLog(@"id = %@",familyVC.ID);

}
- (void)follower
{
    NSLog(@"花儿");
    FamilyViewController *familyVC = [[FamilyViewController alloc] init];
    [self.navigationController pushViewController:familyVC animated:YES];
    TitleModel *model = self.titleArray[3];
    familyVC.ID = model.ID;
    NSLog(@"model = %@",model.name);
    NSLog(@"id = %@",familyVC.ID);

}

- (void)cityLight
{
    NSLog(@"cityLight");
    FamilyViewController *familyVC = [[FamilyViewController alloc] init];
    [self.navigationController pushViewController:familyVC animated:YES];
    TitleModel *model = self.titleArray[4];
    familyVC.ID = model.ID;
    NSLog(@"model = %@",model.name);
    NSLog(@"id = %@",familyVC.ID);

}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
